<include file="public:header"/>
<include file="public:sidebar"/>
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            充值管理 <sub><a href="javascript:history.go(-1)">&lt;返回</a></sub>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li class="active">充值</li>
        </ol>
    </section>
    <hr>
    <!-- Main content -->
    <section class="content">
        <div class="col-md-12">
            <form method="post"
                  class="form-horizontal layui-form" autocomplete="off">
                <div class="box-body">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">
                            <span class="text-danger">*</span>充值金额
                        </label>
                        <div class="col-sm-4">
                            <volist name="list" id="vo">
                                <eq name="vo" value="$selected">
                                    <input type="radio" name="fee" lay-filter="rechange" checked value="{$vo}" title="{$vo}">
                                    <else/>
                                    <input type="radio" name="fee" lay-filter="rechange"  value="{$vo}" title="{$vo}">
                                </eq>
                            </volist>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">
                        </label>
                        <div class="col-sm-4">
                            <div id="qrcode"></div>
                           <h6>充值会收取{$poundage}%的手续费</h6>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">
                        </label>
                        <div class="col-sm-4">
                            <!--<button type="submit" class="btn btn-info" lay-submit lay-filter="*">确定</button>-->
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </section>
</div>
<script src="https://cdn.bootcss.com/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>
<include file="public:footer"/>
<script>
    interval = null;
    $(document).ready( function () {
        init(Number('{$selected}'));
        layui.use(['layer','form'],function () {
            var layer = layui.layer,
                form = layui.form;
            form.on('radio(rechange)', function(data){
                clearInterval(interval);
                init(Number(data.value));
            });
        });
    });
    function init(fee) {
        layui.use(['layer','form'],function () {
            var layer = layui.layer;
            var index = layer.load(1,{
                shade: [0.5,'#000']
            });
            $.post('{:Url("pay/create_order")}',{fee:fee,title:'账号充值',type:2},function (result) {
                layer.close(index);
                if(result.code){
                    layer.msg(result.msg);
                    return false;
                }
                $('#qrcode').empty().qrcode(result.data);
                interval = setInterval(function () {
                    $.post('{:Url("mch/query_order")}',{
                        out_trade_no: result.out_trade_no
                    },function (result) {
                        if(result.code===0){
                            layer.msg(result.msg);
                            clearInterval(interval);
                        }
                    });
                },1000)
            });
        });
    }
</script>